import Entity.DeviceInfo;
import Entity.Notice;
import impl.DeviceOpt;
import impl.NoticeOpt;
import util.MySQLConnection;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.Map;

//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class Main {
    public static void main(String[] args) throws SQLException {
    MySQLConnection.getConnection();
        DeviceInfo device = new DeviceInfo();
        DeviceOpt opt1 = new DeviceOpt();
        Notice notice = new Notice();
        NoticeOpt opt2 = new NoticeOpt();

        //测试1
        device.setId(2);
        device.setName("充电桩-B002改");
        device.setCode("CP20250715066改");
        device.setState("offline改");
        device.setSort(4);
        device.setPosition("泉州信息工程学院改");
        /*增加设备*/
        //opt1.add(device);

        /*删除设备*/
        //opt1.delete(device);

        /*更新设备*/
        //opt1.update(device);

        /*查找设备*/
        //opt1.search(device);

        //测试2
        notice.setId(1);
        notice.setTitle("系统软件");
        notice.setContent("出bug了");
        notice.setDate("2025-07-17");
        notice.setType("软件修复");
        /*增加维修信息*/
        //opt2.add(notice);

        /*删除维修信息*/
        //opt2.delete(notice);

        /*修改维修信息*/
        //opt2.update(notice);

        /*查询维修信息*/
        //opt2.search(notice);

        //文件读取
        Map<String, String> fileMap = readFile();
        fileMap.forEach((key, value) -> System.out.println(key + " = " + value));
        System.out.println(fileMap);
    }



    public static Map<String,String> readFile(){
        Map<String,String> resultMap = new LinkedHashMap<>();
        try(InputStream in = new FileInputStream("D:\\Idea_Jdk\\JavaSpace2\\project15\\src\\file\\info.txt")){
            java.io.BufferedReader reader = new  java.io.BufferedReader(new java.io.InputStreamReader(in));
            String line;
            while ((line = reader.readLine()) != null) {
                String[] parts = line.split(" = ", 2);
                if (parts.length == 2) {
                    resultMap.put(parts[0].trim(), parts[1].trim());
                }
            }
        } catch (IOException e) {
            System.err.println("读取文件时错误: " + e.getMessage());
            e.printStackTrace();
        }
        return resultMap;
    }
}